﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Mobile.Model.Events;
using OgilvyOne.UKNow.Mobile.Utilities;
using OgilvyOne.UKNow.Model;

namespace OgilvyOne.UKNow.Mobile.APIs.Events
{
    public class GetEventCoordinate : IHttpHandler
    {
        public bool IsReusable
        {
            get { return false; }
        }
        public void ProcessRequest(HttpContext context)
        {
            var eventid = context.Request.QueryString["eventid"];
            int eid = 0;
            if(eventid!=null)
            {
                if(int.TryParse(eventid,out eid))
                {
                }
            }
            try
            {
                if (eid > 0)
                {
                    var model = new EventsBLL(2052).selEvent(eid);
                    if (model != null)
                    {
                        var coordinate = new EventCoordinate();
                        coordinate.COL_EVENTS_LATITUDE = model.Lng;
                        coordinate.COL_EVENTS_LONGITUDE = model.Lat;
                        string s = JsonSerializationHelper.ObjectToJson(coordinate);
                        context.Response.Write(ResultUtility.ReturnResultJson("0", s, "获取活动坐标数据成功"));
                    }
                    else
                    {
                        context.Response.Write(ResultUtility.ReturnResultJson("-118", "", "未知的活动"));
                    }
                }
                else
                {
                    context.Response.Write(ResultUtility.ReturnResultJson("-110", "", "参数错误"));
                }


            }
            catch (Exception ex)
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-110", "", "获取活动坐标数据失败. Message:" + ex.Message));

            }
        }
    }
}
